/* This do-file replicates Figure 6 of the paper */ 

cd "" /*input directory here with cleaned data appended_census_mothers using census preparation do-file*/

set more off 

use appended_census_mothers.dta, clear 

********************************************************************************
* Adjust Cohorts to match GHS, see text for detailed explanation * 

gen child_cohort_ghs=child_cohort
replace child_cohort_ghs=child_cohort+1 if yc_birth_month>=7

drop child_cohort 
rename child_cohort_ghs child_cohort 

***************************************************************************************

*****************
* Sample Select *  
*****************
drop if race==3 | race==4 /* Exclude whites and Indian/Asian, who do not receive the CSG, see text */

* Select Windows * 

keep if child_cohort>=1987 & child_cohort<=1998

keep if year==2011

** Exclude missing values ** 

drop if emp==1 & (occupation==. | industry==.) &  (year==2001 | year==2007 | year==2011)
drop if emp==. | activity==.

replace yc_birth_month=99 if yc_birth_month==. /*Indicator variable if month of birth missing */

*********************************************************************************

*******************************
* Define agricultural workers * 
*******************************

gen agr_workers=((industry==1) | (occ_specific==921 & industry==10))


********************************************************************************

gen agr_share=. 
egen child_cohort_d=group(child_cohort)


forvalues j= 0 (1) 1{ 
forvalues i= 1 (1) 12 { 

summarize agr_workers [w=weight] if child_cohort_d==`i' & married==`j'
replace agr_share=r(mean) if child_cohort_d==`i' & married==`j'

}

}

*********
* Fig 6 *
*********

cd "C:\Users\alessandro\Il mio Drive\CSG impact on Job quality\WBER\Replication package\Figures"

egen tag=tag(child_cohort married)

forvalues j= 0 (1) 1 { 

preserve 

keep if married==`j'

twoway (lfitci agr_workers child_cohort [aw=weight] if child_cohort<1993, range(. 1993) ciplot(rline) lcolor(black) clwidth(medthick)  alcolor(gs10) alstyle(none) alpattern(dash)  fcolor(none))  ///
|| (lfitci agr_workers child_cohort [aw=weight] if child_cohort>=1993 ,  ciplot(rline) lcolor(black) clwidth(medthick)  alcolor(gs10) alstyle(none) alpattern(dash)  fcolor(none)) ///
|| (scatter agr_share child_cohort if tag==1, xlabel(1987 (2) 1998) xline(1993, lcolor(black)) graphregion( color(white) ) plotregion(fcolor(white) ) msize(small) mcolor(black) ) ///
||, legend(off) xtitle("") ylabel(0 (0.01) 0.08)

graph export Tondini_fig6_`j'.png, replace

restore
}
